CREATE PROCEDURE [dbo].[sp_cat_GetFamily]
@Family varchar(50) = NULL, @PKFamily int = NULL
AS
BEGIN
  SELECT PKFamily , Family FROM CT_Family
  WHERE PKFamily = COALESCE(@PKFamily , PKFamily)
  AND (Family LIKE '% '+@Family+'%' OR Family LIKE @Family+'%')
  ORDER BY 
    CASE 
      WHEN Family = @Family THEN 0
      WHEN Family LIKE @Family+'%' THEN 1
      ELSE 2
     END
     , Family;
END